﻿using System;
using System.Data;
using System.Collections;
using System.Reflection;

/// <summary>
/// Summary description for ObjectConverter
/// </summary>
public class ObjectConverter
{
	public ObjectConverter()
	{
		//
		// TODO: Add constructor logic here
		//
	} //eof constructor 

//not in use YET 
	private DataTable ConvertIEnumerableToDataTable ( IEnumerable dataSource )
	{
			System.Reflection.PropertyInfo[] propInfo = null;
			DataTable dt = new DataTable ();

			foreach (object o in dataSource)
			{
					propInfo = o.GetType ().GetProperties ();

					for (int i = 0; i < propInfo.Length; i++)
					{
							dt.Columns.Add ( propInfo [ i ].Name );
					}
					break;
			}

			foreach (object tempObject in dataSource)
			{
					DataRow dr = dt.NewRow ();
					for (int i = 0; i < propInfo.Length; i++)
					{
							object t = tempObject.GetType ().InvokeMember ( propInfo [ i ].Name , BindingFlags.GetProperty , null , tempObject , new object [] { } );
							if (t != null)
									dr [ i ] = t.ToString ();
					}
					dt.Rows.Add ( dr );
			}
			return dt;
	} //eof method 
} //eof class 
